package leetcode.code;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution1816 implements IDebug {

	public String truncateSentence(String s, int k) {
		int p = 0;
		char[] chars = s.toCharArray();
		while (k > 0 && p < chars.length) {
			if (chars[p++] == ' ') {
				k--;
			}
		}
		return k > 0 ? s : new String(chars, 0, p - 1);
	}

	@Override
	public void debug1() {
		HelpDebug.compare("Hello how are you", this.truncateSentence("Hello how are you Contestant", 4));

	}

	@Override
	public void debug2() {
		HelpDebug.compare("chopper is not a tanuki", this.truncateSentence("chopper is not a tanuki", 5));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution1816 so = new Solution1816();
		so.debug1();
		so.debug2();
	}

}
